package mo.leetcode_top;

public class L540 {

    public int singleNonDuplicate(int[] nums) {
        int res = nums[0];
        for (int i = 1; i < nums.length; i++) {
            res ^= nums[i];
        }
        return res;
    }


    public int singleNonDuplicate2(int[] nums) {
        int low = 0;
        int high = nums.length - 1;
        while (low < high) {
            int mid = low + (high - low) / 2;
            if (mid % 2 != 0) {
                mid = mid - 1;
            }
            if (nums[mid] == nums[mid+1]) {
                low = mid + 2;
            } else {
                high = mid;
            }
        }

        return high;
    }

}
